package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 条件查询
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);
    /**
     * 更加套菜id查询菜品
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    /**
     * 根据菜品id删除菜单
     */
    @Delete("delete from setmeal_dish where dish_id=#{id}")
    void deleteByDishId(Long id);

    /**
     * 根据才能id获得逃单
     *
     * @param id
     * @return
     */
    @Select("select setmeal_id from setmeal_dish where dish_id = #{dishId}")
    List<Long> getSetmealIdsByDishId(Long id);

    /**
     * 套餐分页查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageById(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id查询信息
     *
     * @param id
     * @return
     */
    SetmealVO selectById(Long id);

    /**
     * 添加一个套餐
     *
     * @param
     */
    @AutoFill(OperationType.INSERT)
    void add(Setmeal setmeal);

    /**
     * 查询套餐通过分类表
     *
     * @param id
     * @return
     */
    @Select("select * from setmeal where category_id=#{id}")
    List<Setmeal> getSetmealByCategoryId(Long id);

    /**
     * 更新套餐
     *
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 删除套餐
     *
     * @param id
     */
    @Delete("delete from setmeal where id=#{id}")
    void delete(Long id);

    /**
     * 更高套餐状态
     * @param build
     */

    @Update("update setmeal set status=#{status} where id=#{id}")
    void updateStatus(Setmeal build);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("SELECT * from setmeal where id=#{id} ")
    Setmeal getById(Long id);

    /**
     * 查询启用数量
     * @return
     */
    SetmealOverViewVO selectOverviewSetmeals();

    /**
     * 查询菜品总览
     * @return
     */
    DishOverViewVO selectOverviewDish();

    /**
     * 菜品状态查询
     * @return
     */
    OrderOverViewVO selectOverviewOrders();
}
